package com.yanqu.road.server.logic.activity.condition.turtle;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;

import java.math.BigInteger;

/**
 * @Author : Cxp
 * @Time : 2024-09-11
 * @Description : 乌龟对对碰-个人积分排行
 */

public class TurtleUserRankCondition extends BaseNewRankActivityCondition {

    public TurtleUserRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        long arg = (long) object;
        if (arg <= 0) {
            return;
        }
        BigInteger value = BigInteger.valueOf(arg);
        if (value.compareTo(getValue()) > 0) {
            setValue(value);
            // 重新生成排行榜
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.TurtleUserRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.TurtleUserRank.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo) {
        return ActivityMgr.activityInShowTime(activityInfo);
    }
}
